import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';
import 'package:share_plus/share_plus.dart';
import 'package:smart_translator/app/modules/photoTranslate/controllers/utilsFile.dart';

import '../../../utils/tips.dart';

class DialogView extends Dialog {
  final String srcLang;
  final String tgtLang;
  final String srcText;
  final String tgtText;
  final String srcCode;
  final String tgtCode;
  final translateVoice;

  const DialogView({
    Key? key,
    required this.srcLang,
    required this.tgtLang,
    required this.srcText,
    required this.tgtText,
    required this.srcCode,
    required this.tgtCode,
    required this.translateVoice,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Container(
          padding: EdgeInsets.fromLTRB(20, 16, 20, 16),
          height: 56,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Expanded(
                child: Center(
                  child: Text(
                    '翻译',
                    style: TextStyle(
                      fontSize: 16.0,
                      color: Color(0xFF333333),
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                ),
              ),
              InkWell(
                child: Image.asset(
                  'assets/images/icon_poup_window_close.png',
                  width: 10.w,
                  height: 10.h,
                ),
                onTap: () {
                  PhotoUtil.clearVoiceFile();
                  Navigator.pop(context);
                },
              ),
            ],
          ),
        ),

        Expanded(
          child: Column(
            children: [
              Expanded(
                child: Padding(
                  padding: EdgeInsets.all(20.0),
                  child: Container(
                    padding: EdgeInsets.all(16.0),
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(8.0),
                      boxShadow: [
                        BoxShadow(
                          color: Color(0xFFF3F2F8),
                          blurRadius: 10.0,
                          offset: Offset(0.0, 0.0),
                        ),
                      ],
                    ),
                    child: Column(
                      children: [
                        Row(
                          children: [
                            Text(
                              srcLang,
                              style: TextStyle(color: Color(0xFF8A8A8E)),
                            ),
                            Expanded(child: Container()),
                            InkWell(
                              child: Image.asset(
                                'assets/images/icon_audio_play_btn.png',
                                width: 16.w,
                                height: 16.h,
                              ),
                              onTap: () {
                                translateVoice(srcText,srcCode);
                                print('check ${srcText} ${srcCode}');
                              },
                            ),
                          ],
                        ),
                        SizedBox(height: 16),
                        Expanded(
                          child: Align(alignment: Alignment.topLeft,
                          child:Text(
                            srcText,
                            style: TextStyle(
                              color: Color(0xFF333333),
                              fontWeight: FontWeight.w600,
                            ),
                          )),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
              SizedBox(height: 16),
              Expanded(
                child: Padding(
                  padding: EdgeInsets.all(20.0),
                  child: Container(
                    padding: EdgeInsets.all(16.0),
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(8.0),
                      boxShadow: [
                        BoxShadow(
                          color: Color(0xFFF3F2F8),
                          blurRadius: 10.0,
                          offset: Offset(0.0, 0.0),
                        ),
                      ],
                    ),
                    child: Column(
                      children: [
                        Row(
                          children: [
                            Text(
                              tgtLang,
                              style: TextStyle(color: Color(0xFF8A8A8E)),
                            ),
                            Expanded(child: Container()),
                            InkWell(
                              child: Image.asset(
                                'assets/images/icon_audio_play_btn.png',
                                width: 16.w,
                                height: 16.h,
                              ),
                              onTap: () {
                                translateVoice(tgtText,tgtCode);
                                print('check ${tgtText} ${tgtCode}');
                              },
                            ),
                          ],
                        ),
                        SizedBox(height: 16),
                        Expanded(
                          child: Align(alignment: Alignment.topLeft,
                            child: Text(
                              tgtText,
                              textDirection: TextDirection.ltr,
                              style: TextStyle(
                                color: Color(0xFF333333),
                                fontWeight: FontWeight.w600,
                              ),
                            ),)

                        ),
                        Column(
                          children: [

                            Row(
                              children: [
                                InkWell(
                                  child: Row(
                                    children: [
                                      Image.asset(
                                        'assets/images/icon_script_bottom_menu_copy.png',
                                        width: 16.w,
                                        height: 16.h,
                                      ),
                                      SizedBox(width: 16),
                                      Text('复制'),
                                    ],
                                  ),

                                  onTap: () async {
                                    await Clipboard.setData(ClipboardData(text: tgtText));
                                    Tips.showToast('文本已复制到粘贴板');
                                  },
                                ),

                              ],
                            ),
                            Divider(),
                            SizedBox(height:5),
                            InkWell(
                              child: Row(
                                children: [
                                  Image.asset(
                                    'assets/images/icon_audio_upload.png',
                                    width: 16.w,
                                    height: 16.h,
                                  ),
                                  SizedBox(width: 16),
                                  Text('分享'),
                                ],
                              ),

                              onTap: ()  {
                                SharePlus.instance.share(ShareParams(text:tgtText, title: '分享文本'));
                              },
                            ),
                            // Row(children: [Text('分享')],)
                          ],
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }
}
